#include<iostream>
#include<string>
#include<fstream>

using namespace std;

int dat[6] = { 0 };		   //存储0字符，1单词，2句子
char txtaddress[50];       //文件地址
char mode;                 //c字符，w单词，d句子，m全部
int comlines = 0;          //注释行标志位
int ifblank = 0;           //空行标志位

int dischar(fstream& outtxt, int* dat)  //统计函数
{
	char str[50];          
	while (outtxt.getline(str, 50))
	{
		for (int i = 0; i < strlen(str); i++) //统计字符数
			if ((str[i] >= 'A' && str[i] <= 'z') || (str[i] >= '0' && str[i] <= '9') ||
				str[i] == '.' || str[i] == ',' || str[i] == '?' || str[i] == '!' || str[i] == '/' || str[i] == '*')
					dat[0]++;
	}
	return 0;
}


int disword(fstream& outtxt, int* dat)  //统计函数
{
	char str[50];          
	while (outtxt.getline(str, 50))
	{
		for (int i = 0; i < strlen(str); i++) //统计单词数
			if (str[i] >= 'A' && str[i] <= 'z')
				if (str[i + 1] <= 'A' || str[i + 1] >= 'z')
					dat[1]++;
	}
	return 0;
}

int dissent(fstream& outtxt, int* dat)  //统计函数
{
	char str[50];          
	while (outtxt.getline(str, 50))
	{
		for (int i = 0; i < strlen(str); i++)//统计句子
			if ((str[i] == '.' && str[i + 1] != '.') || (str[i] == '!' && str[i + 1] != '!'))
				dat[2]++;
	}
	return 0;
}

int display(fstream& outtxt, int* dat)  //统计函数
{
	char str[50];             
	while (outtxt.getline(str, 50))
	{
		for (int i = 0; i < strlen(str); i++)
		{
			if ((str[i] >= 'A' && str[i] <= 'z') || (str[i] >= '0' && str[i] <= '9') ||  //统计字符数
				str[i] == '.' || str[i] == ',' || str[i] == '?' || str[i] == '!' || str[i] == '/' || str[i] == '*')
			{
				dat[0]++;
				ifblank++;   //使本行不是空行
			}
			if (str[i] >= 'A' && str[i] <= 'z')   //统计单词数
				if (str[i + 1] <= 'A' || str[i + 1] >= 'z')
					dat[1]++;
			if ((str[i] == '.' && str[i + 1] != '.') )//统计句子数
				dat[2]++;
			{
				comlines = 0; 
				dat[5]++;
			}
		}
		ifblank = 0;         
	}
	return 0;
}
int main()
{
while (1)
	{
		cout << "wc.exe -";
		cin >> mode;                             //选择模式
		cin >> txtaddress;                       //写入地址

		fstream outtxt(txtaddress, ios::in);     
		if (mode == 'c')
		{
			dischar(outtxt, dat);                     //字符统计函数
			cout << "characters: " << dat[0] << endl;
		}
		else if (mode == 'w')
		{
			disword(outtxt, dat);                      //单词统计函数
			cout << "words:" << dat[1] << endl;
		}
		else if (mode == 'd')
		{
			dissent(outtxt, dat);                      //句子统计函数
			cout << "sentence:" << dat[2] << endl;
		}
		else if (mode == 'm')
		{
			display(outtxt, dat);                     //统计函数
			cout << "characters: " << dat[0] << endl;
			cout << "words:" << dat[1] << endl;
			cout << "sentence:" << dat[2] << endl;
		}
		cout << endl;
		outtxt.close();
	}
    
	system("pause");
	return 0;

}